#lang racket

(define (sqrt-iter guess x)
  (if (good-enough? guess x)
      guess
      (sqrt-iter(improve guess x)
                x)))

(define (improve guess x)
  (average guess (/ x guess)))

(define (average x y)
  (/ (+ x y) 2))

(define (good-enough? guess x)
  (< (abs (- (square guess) x)) 0.001))

(define (square x) (* x x))

(define (sqrt x) (sqrt-iter 1.0 x))

(sqrt 2)

(define (good-enough2? guess1 guess2)
  (< (abs (- guess1 guess2)) 0.001))

(define (sqrt-iter2 guess x)
  (if(good-enough2? guess (improve guess x))
     guess
     (sqrt-iter2 (improve guess x)
                 x)))

(define (sqrt2 x)
  (sqrt-iter2 1.0 x))

(sqrt2 2)
